package com.xingdata.jjxc.m.avt;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ab.http.AbHttpUtil;
import com.ab.http.AbRequestParams;
import com.ab.http.AbStringHttpResponseListener;
import com.alibaba.fastjson.JSON;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.maps.AMap;
import com.amap.api.maps.AMap.InfoWindowAdapter;
import com.amap.api.maps.AMap.OnInfoWindowClickListener;
import com.amap.api.maps.AMap.OnMapClickListener;
import com.amap.api.maps.AMap.OnMapLoadedListener;
import com.amap.api.maps.LocationSource;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.Marker;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.AMapNaviListener;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapNaviCross;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviPath;
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.amap.api.navi.view.RouteOverLay;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.geocoder.GeocodeAddress;
import com.amap.api.services.geocoder.GeocodeQuery;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.GeocodeSearch.OnGeocodeSearchListener;
import com.amap.api.services.geocoder.RegeocodeQuery;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.amap.api.services.help.Inputtips;
import com.amap.api.services.help.Inputtips.InputtipsListener;
import com.amap.api.services.help.Tip;
import com.autonavi.tbt.NaviStaticInfo;
import com.autonavi.tbt.TrafficFacilityInfo;
import com.xingdata.jjxc.App;
import com.xingdata.jjxc.R;
import com.xingdata.jjxc.enty.NaviLatLngEntity;
import com.xingdata.jjxc.enty.RespEntity;
import com.xingdata.jjxc.utils.Code;
import com.xingdata.jjxc.utils.Log;
import com.xingdata.jjxc.utils.SystemInfo;

public class ComAddressListavt extends Activity implements LocationSource,
		AMapLocationListener, OnMapClickListener, OnGeocodeSearchListener,
		OnItemClickListener, OnClickListener, InfoWindowAdapter, TextWatcher,
		OnInfoWindowClickListener, AMapNaviListener, OnMapLoadedListener {
	private TextView icon_tv, title;
	private RelativeLayout icon_l;

	private String lat = null;// 纬度
	private String lon = null;// 经度
	private String address_name = null;// 实际名称
	private String site_id = null;// 编号
	private String address = null;// 实际地址
	private String state_anv = "";
	private String areaid = null;// 实际地区

	protected AbHttpUtil mAbHttpUtil = null;
	protected AbRequestParams params = null;
	protected RespEntity resp = null;
//	protected UserEntity user;
//	protected String[] info;

	private TextView com_find_map_tv;

	private String TAG = "TestActivity";
	private AMap aMap;
	private AMapNavi mAmapNavi;
	private MapView con_list_bmapView;
	private OnLocationChangedListener mListener;
//	private LocationManagerProxy mAMapLocationManager;
	// 搜索重新封装的数据
	private List<Tip> tips = null;
	private Bundle mBundle;
	// 适配器中的数据
	private List<String> adaList = new ArrayList<String>();
	private View pop_view;
	// // 驾车路径规划起点，途经点，终点的list
	private List<NaviLatLng> mStartPoints = new ArrayList<NaviLatLng>();
	private List<NaviLatLng> mEndPoints = new ArrayList<NaviLatLng>();
	// // 记录起点、终点、途经点位置
	private NaviLatLng mStartPoint = new NaviLatLng();
	private NaviLatLng mEndPoint = new NaviLatLng();

	// // 记录起点、终点、途经点在地图上添加的Marker
	private Marker mStartMarker;
	private Marker mWayMarker;
	private Marker mEndMarker;
	private Marker mGPSMarker;
	// 坐标/地名转换
	private GeocodeSearch geocoderSearch;
	// 记录地图点击事件相应情况，根据选择不同，地图响应不同
	private int mMapClickMode = MAP_CLICK_NO;
	private static final int MAP_CLICK_NO = 0;// 地图不接受点击事件
	private static final int MAP_CLICK_END = 3;// 地图点击设置终点

	// 传到添加常用地址的界面
	private String addname_seach;
	private String lat_seach, lon_seach;

	/**
	 * 搜索的具体地址
	 */
	private String addressName;
	public static LatLng ZHENGZHOU = null;

	private boolean mIsCalculateRouteSuccess = false;
	// 是否驾车和是否计算成功的标志
	private boolean mIsDriveMode = true;
	private AMapNavi mAMapNavi;
	private RouteOverLay mRouteOverLay;
	private int inMultiple = 100000;

	private boolean mIsMapLoaded = false;

	// 算路距离
	String navPath = "";

	private TextView pop_address_nav_tv;

	private RelativeLayout add_seach_rl, add_list_rl;

	// 搜索框
	private AutoCompleteTextView serchEditText;
	// 搜索适配器
	private ArrayAdapter serchAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_com_address_listavt);
		con_list_bmapView = (MapView) findViewById(R.id.con_list_bmapView);
		con_list_bmapView.onCreate(savedInstanceState);

		add_seach_rl = (RelativeLayout) findViewById(R.id.add_seach_rl);
		add_list_rl = (RelativeLayout) findViewById(R.id.add_list_rl);

		// 获取Http工具类
		mAbHttpUtil = AbHttpUtil.getInstance(this);
		mAbHttpUtil.setDebug(true);
		mAbHttpUtil.setTimeout(15000);
		// BaiduNaviManager.getInstance().
//		user = SP.getUserInfo(this);
//		info = SP.getMobileAndPassword(this);

		initDateBeforSetContentView();

		init();
		initMapAndNavi();

	}

	private void initDateBeforSetContentView() {
		Bundle bundle = getIntent().getExtras();
		state_anv = bundle.getString("state_anv");

		lat = bundle.getString("lat");// 纬度39.9091
		lon = bundle.getString("lon");// 经度116.4618
		address_name = bundle.getString("address_name");// 自定义名称//北京市朝阳区国贸(地铁站)
		address = bundle.getString("address");// 实际地址 北京市朝阳区国贸(地铁站)

		if ("2".equals(state_anv)) {// 2为常用地址 1为首页到此页面
			site_id = bundle.getString("site_id");// 编号43
			add_list_rl.setVisibility(View.VISIBLE);
			add_seach_rl.setVisibility(View.INVISIBLE);
		} else if ("1".equals(state_anv)) {
			add_list_rl.setVisibility(View.INVISIBLE);
			add_seach_rl.setVisibility(View.VISIBLE);

		}

	}

	/**
	 * 初始化地图和导航相关内容
	 */
	private void initMapAndNavi() {
		// 初始化Marker添加到地图
		mStartMarker = aMap.addMarker(new MarkerOptions()
				.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
						.decodeResource(getResources(), R.drawable.start))));
		mWayMarker = aMap.addMarker(new MarkerOptions()
				.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
						.decodeResource(getResources(), R.drawable.way))));
		// 动画效果
		ArrayList<BitmapDescriptor> giflist = new ArrayList<BitmapDescriptor>();
		// giflist.add(BitmapDescriptorFactory
		// .defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
		giflist.add(BitmapDescriptorFactory
				.defaultMarker(BitmapDescriptorFactory.HUE_RED));
		// giflist.add(BitmapDescriptorFactory
		// .defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));

		mEndMarker = aMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f)
				.position(ZHENGZHOU).title("").icons(giflist).draggable(true)
				.period(10));
		mGPSMarker = aMap.addMarker(new MarkerOptions()
				.icon(BitmapDescriptorFactory.fromBitmap(BitmapFactory
						.decodeResource(getResources(),
								R.drawable.location_marker))));

		/**
		 * 初始化
		 */
		mAMapNavi = AMapNavi.getInstance(this);
		mAMapNavi.setAMapNaviListener(this);

		double d_lat = Double.parseDouble(lat);
		double d_lon = Double.parseDouble(lon);
		ZHENGZHOU = new LatLng(d_lat, d_lon);

		if ("2".equals(state_anv)) {// 2为常用地址 1为首页到此页面
			// 搜索完毕后根据坐标点画出
			addPointToMap(new LatLng(d_lat, d_lon));
			regeocodeQuery(new LatLonPoint(d_lat, d_lon));
		} else if ("1".equals(state_anv)) {

		}

	}

	private void init() {
		icon_l = (RelativeLayout) findViewById(R.id.icon_l);
		icon_l.setOnClickListener(this);
		title = (TextView) findViewById(R.id.title);
		title.setText(address_name);
//		icon_tv = (TextView) findViewById(R.id.icon_tv);
//		icon_tv.setText("删除");
		icon_tv.setOnClickListener(this);

		mMapClickMode = MAP_CLICK_END;

		if (aMap == null) {
			aMap = con_list_bmapView.getMap();
			setUpMap();
		}

		serchEditText = (AutoCompleteTextView) findViewById(R.id.com_search_map_et);
		geocoderSearch = new GeocodeSearch(this);
		// 输入提示的监听接口
		serchEditText.addTextChangedListener(this);
		serchEditText.setOnItemClickListener(this);
		geocoderSearch = new GeocodeSearch(this);
		// 地名搜索监听接口
		geocoderSearch.setOnGeocodeSearchListener(this);

		mRouteOverLay = new RouteOverLay(aMap, null,this);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {

		case R.id.icon_l:
			finish();
			break;
//		case R.id.icon_tv:
//			doPost_deleteeName(address_name, areaid, address, lon, lat);
//			break;

		default:
			break;
		}
	}

	/**
	 * 根据地名艘搜索坐标 第一个参数表示地址，第二个参数表示查询城市，中文或者中文全拼，citycode、adcode
	 */
	private void geocodeQuery(String address, String cityCode) {
		GeocodeQuery query = new GeocodeQuery(address, cityCode);
		geocoderSearch.getFromLocationNameAsyn(query);
	}

	/**
	 * 根据坐标点搜索地名 第一个参数表示一个Latlng，第二参数表示范围多少米，第三个参数表示是火系坐标系还是GPS原生坐标系
	 */
	private void regeocodeQuery(LatLonPoint latLonPoint) {
		RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,
				GeocodeSearch.AMAP);
		geocoderSearch.getFromLocationAsyn(query);
	}

	private void setUpMap() {
		aMap.setLocationSource(this);// 设置定位监听
		aMap.getUiSettings().setMyLocationButtonEnabled(true);// 设置默认定位按钮是否显示
		aMap.setMyLocationEnabled(true);// 设置为true表示显示定位层并可触发定位，false表示隐藏定位层并不可触发定位，默认是false
		// 设置定位的类型为定位模式：定位（AMap.LOCATION_TYPE_LOCATE）、跟随（AMap.LOCATION_TYPE_MAP_FOLLOW）
		// 地图根据面向方向旋转（AMap.LOCATION_TYPE_MAP_ROTATE）三种模式
		aMap.setMyLocationType(AMap.LOCATION_TYPE_LOCATE);

		aMap.setOnMapClickListener(this);
		aMap.setOnInfoWindowClickListener(this);
		aMap.setInfoWindowAdapter(this);// 设置自定义InfoWindow样式

	}

	/**
	 * 定位成功后回调函数
	 */
	@Override
	public void onLocationChanged(AMapLocation amapLocation) {

		if (mListener != null && amapLocation != null) {
			if (amapLocation.getErrorCode() == 0) {
				mListener.onLocationChanged(amapLocation);// 显示系统小蓝点
				mStartPoint.setLatitude(amapLocation.getLatitude());
				mStartPoint.setLongitude(amapLocation.getLongitude());

			}
		}

	}

	/**
	 * 激活定位
	 */
	@Override
	public void activate(OnLocationChangedListener listener) {
//		mListener = listener;
//		if (mAMapLocationManager == null) {
//			mAMapLocationManager = LocationManagerProxy.getInstance(this);
//			// 此方法为每隔固定时间会发起一次定位请求，为了减少电量消耗或网络流量消耗，
//			// 注意设置合适的定位时间的间隔，并且在合适时间调用removeUpdates()方法来取消定位请求
//			// 在定位结束后，在合适的生命周期调用destroy()方法
//			// 其中如果间隔时间为-1，则定位只定一次
//			mAMapLocationManager.requestLocationData(
//					LocationProviderProxy.AMapNetwork, 60 * 1000, 10, this);
//		}
	}

	/**
	 * 停止定位
	 */
	@Override
	public void deactivate() {
//		mListener = null;
//		if (mAMapLocationManager != null) {
//			mAMapLocationManager.removeUpdates(this);
//			mAMapLocationManager.destroy();
//		}
//		mAMapLocationManager = null;
	}

	/**
	 * 此方法需存在
	 */
	@Override
	protected void onResume() {
		super.onResume();
		con_list_bmapView.onResume();
	}

	/**
	 * 此方法需存在
	 */
	@Override
	protected void onPause() {
		super.onPause();
		con_list_bmapView.onPause();
		deactivate();
	}

	/**
	 * 此方法需存在
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		con_list_bmapView.onDestroy();
	}

	@Override
	public void onMapClick(LatLng latLng) {
		mMapClickMode = MAP_CLICK_NO;
		// 默认不接受任何操作
		if (mMapClickMode == MAP_CLICK_NO) {
			return;
		}
		// 其他情况根据起点、途经点、终点不同逻辑处理不同
		addPointToMap(latLng);

		regeocodeQuery(new LatLonPoint(latLng.latitude, latLng.longitude));
		Log.i(TAG, "latitude:" + latLng.latitude + " longitude:"
				+ latLng.longitude);

	}

	/**
	 * 画出坐标点
	 * 
	 * @param latLng
	 */
	private void addPointToMap(LatLng latLng) {

		NaviLatLng naviLatLng = new NaviLatLng(latLng.latitude,
				latLng.longitude);

		switch (mMapClickMode) {
		// 终点
		case MAP_CLICK_END:
			mEndMarker.setPosition(latLng);
			mEndPoints.clear();
			mEndPoint = naviLatLng;
			mEndPoints.add(mEndPoint);

			mEndMarker.showInfoWindow();// ******
			break;
		}

	}

	private void setnavPath() {
		NaviLatLngEntity startNaviLatLng = new NaviLatLngEntity();
		startNaviLatLng.setLatitude(mStartPoint.getLatitude());
		startNaviLatLng.setLongitude(mStartPoint.getLongitude());

		NaviLatLngEntity endLatLngEntity = new NaviLatLngEntity();
		endLatLngEntity.setLatitude(mEndPoint.getLatitude());
		endLatLngEntity.setLongitude(mEndPoint.getLongitude());

		mBundle = new Bundle();
		mBundle.putSerializable("start", startNaviLatLng);
		mBundle.putSerializable("end", endLatLngEntity);

		// 起点终点坐标
		NaviLatLng mNaviStart = null;
		NaviLatLng mNaviEnd = null;

		mNaviStart = new NaviLatLng(
				((NaviLatLngEntity) mBundle.getSerializable("start"))
						.getLatitude(),
				((NaviLatLngEntity) mBundle.getSerializable("start"))
						.getLongitude());
		mNaviEnd = new NaviLatLng(
				((NaviLatLngEntity) mBundle.getSerializable("end"))
						.getLatitude(),
				((NaviLatLngEntity) mBundle.getSerializable("end"))
						.getLongitude());
		mStartPoints.add(mNaviStart);
		mEndPoints.add(mNaviEnd);

		/**
		 * 路线规划
		 */
		mIsCalculateRouteSuccess = false;
		mIsDriveMode = true;
		calculateDriveRoute();

	}

	@Override
	public void onGeocodeSearched(GeocodeResult result, int rCode) {
		if (rCode == 0) {
			if (result != null && result.getGeocodeAddressList() != null
					&& result.getGeocodeAddressList().size() > 0) {
				GeocodeAddress address = result.getGeocodeAddressList().get(0);
				String addressName = "经纬度值:" + address.getLatLonPoint()
						+ "\n位置描述:" + address.getFormatAddress();

				lat_seach = String.valueOf(address.getLatLonPoint()
						.getLatitude());
				lon_seach = String.valueOf(address.getLatLonPoint()
						.getLongitude());
				// 搜索完毕后根据坐标点画出
				addPointToMap(new LatLng(
						address.getLatLonPoint().getLatitude(), address
								.getLatLonPoint().getLongitude()));

				addname_seach = address.getFormatAddress();
				showToast(addname_seach);

			} else {
				showToast("没有搜索到结果");
			}

		} else {
			showToast("网络异常");
		}
	}

	@Override
	public void onRegeocodeSearched(RegeocodeResult result, int rCode) {
		if (rCode == 0) {
			if (result != null && result.getRegeocodeAddress() != null
					&& result.getRegeocodeAddress().getFormatAddress() != null) {
				addressName = result.getRegeocodeAddress().getFormatAddress()
						+ "附近";
				// showToast(addressName);

			} else {
				showToast("没有搜索到地址");
			}
		} else {
			showToast("网络异常");
		}
	}

	private void showToast(String t) {
		Log.i(TAG, t);
		Toast.makeText(ComAddressListavt.this, t, Toast.LENGTH_LONG).show();
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View view, int position,
			long id) {
		Log.i(TAG,
				"NAME:" + tips.get(position).getName() + "  District:"
						+ tips.get(position).getDistrict() + " Adcode:"
						+ tips.get(position).getAdcode());
		geocodeQuery(tips.get(position).getName(), tips.get(position)
				.getAdcode());
	}

	

	@Override
	public View getInfoContents(Marker marker) {

		View infoContent = getLayoutInflater().inflate(
				R.layout.pop_car_address_set, null);
		return infoContent;
	}

	@Override
	public View getInfoWindow(Marker marker) {

		View infoWindow = getLayoutInflater().inflate(
				R.layout.pop_car_address_navigation, null);

//		TextView pop_name_nav = ((TextView) infoWindow
//				.findViewById(R.id.pop_company_namenav_tv));
//		TextView pop_address_nav = ((TextView) infoWindow
//				.findViewById(R.id.pop_company_addressnac_tv));
//		pop_address_nav_tv = (TextView) infoWindow
//				.findViewById(R.id.pop_address_nav_tv);
//
//		RelativeLayout pop_address_nav_rl = (RelativeLayout) infoWindow
//				.findViewById(R.id.pop_address_nav_rl);
//
//		pop_name_nav.setText(address_name);
//		// pop_address_nav.setText(addname_seach);//现在搜索的具体位置
//		pop_address_nav.setText(address);// 传过来的地址
//
//		new Handler().postDelayed(new Runnable() {
//			@Override
//			public void run() {
//				if ("2".equals(state_anv)) {
//					setnavPath();
//				}
//
//			}
//		}, 3000);
//
//		pop_address_nav_rl.setOnClickListener(new OnClickListener() {
//
//			@Override
//			public void onClick(View v) {
//
//				NaviLatLngEntity startNaviLatLng = new NaviLatLngEntity();
//				startNaviLatLng.setLatitude(mStartPoint.getLatitude());
//				startNaviLatLng.setLongitude(mStartPoint.getLongitude());
//
//				NaviLatLngEntity endLatLngEntity = new NaviLatLngEntity();
//				endLatLngEntity.setLatitude(mEndPoint.getLatitude());
//				endLatLngEntity.setLongitude(mEndPoint.getLongitude());
//
//				if ("0.0".equals(mStartPoint.getLatitude())
//						|| "0.0".equals(mStartPoint.getLongitude())
//						|| "0.0".equals(mStartPoint.getLatitude())
//						|| "0.0".equals(mStartPoint.getLongitude())) {
//					showToast("请重新算路");
//					return;
//
//				}
//				// 传经纬度
//				mBundle = new Bundle();
//				mBundle.putDouble("startLat", mStartPoint.getLatitude());
//				mBundle.putDouble("startLon", mStartPoint.getLongitude());
//				mBundle.putDouble("endLat", mEndPoint.getLatitude());
//				mBundle.putDouble("endLon", mEndPoint.getLongitude());
//
//				Intent gpsNaviIntent = new Intent(ComAddressListavt.this,
//						SimpleGPSNaviActivity.class);
//				gpsNaviIntent.putExtras(mBundle);
//				startActivity(gpsNaviIntent);
//
//				// Intent routeIntent = new Intent(ComAddressListavt.this,
//				// SimpleNaviRouteActivity.class);// 模拟导航
//				// routeIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//				// startActivity(routeIntent);
//				// routeIntent.putExtras(mBundle);
//
//				// Intent gpsNaviIntent = new Intent(ComAddressListavt.this,
//				// SimpleGPSNaviActivity.class);// 直接导航
//				// gpsNaviIntent.putExtras(mBundle);
//				// startActivity(gpsNaviIntent);
//
//			}
//
//		});
		return infoWindow;
	}

	// 计算驾车路线
	private void calculateDriveRoute() {
		boolean isSuccess = mAMapNavi.calculateDriveRoute(mStartPoints,
				mEndPoints, null, AMapNavi.DrivingDefault);
		if (!isSuccess) {
			showToast("路线计算失败,检查参数情况");
		}

	}

	@Override
	public void onInfoWindowClick(Marker marker) {

	}

	private void doPost_deleteeName(String nick_address, String areaid,
			String address, String longitude, String latitude) {
		if (isNetworkConnected() == false) {
			Toast.makeText(ComAddressListavt.this, "网络连接断开，请检查网络",
					Toast.LENGTH_LONG).show();
			return;
		}
		resp = null;
		params = new AbRequestParams();
		params.put("access_token", Code.accessToken());
		params.put("userid", SystemInfo.getUserInfo().getUserid());
		params.put("site_id", site_id);
		params.put("nick_address", nick_address);
		params.put("areaid", areaid);
		params.put("address", address);
		params.put("longitude", longitude);
		params.put("latitude", latitude);
		params.put("maptype", "2");// 为高德地图
		params.put("flag", "9");

		mAbHttpUtil.post(App.ZZD_REQUEST_CHANGENAME, params,
				new AbStringHttpResponseListener() {
					@Override
					public void onSuccess(int statusCode, String content) {
						resp = JSON.parseObject(content, RespEntity.class);
					}

					@Override
					public void onFailure(int statusCode, String content,
							Throwable error) {
					}

					@Override
					public void onStart() {
						super.onStart();
					}

					@Override
					public void onFinish() {
						if (resp != null) {
							if (resp.getState() == 0) {
								Toast.makeText(ComAddressListavt.this, "删除成功",
										Toast.LENGTH_LONG).show();
								setResult(RESULT_OK);
								finish();
							} else if (resp.getState() == 1) {

								Toast.makeText(ComAddressListavt.this,
										resp.getMsg(), Toast.LENGTH_LONG)
										.show();
							} else {
								Toast.makeText(ComAddressListavt.this,
										resp.getMsg(), Toast.LENGTH_LONG)
										.show();
							}
						} else {
							Toast.makeText(ComAddressListavt.this, "网络超时，请重试",
									Toast.LENGTH_LONG).show();
							return;
						}
					}
				});
	}

	protected boolean isNetworkConnected() {

		ConnectivityManager cwjManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

		cwjManager.getActiveNetworkInfo();
		boolean netSataus = true;
		if (cwjManager.getActiveNetworkInfo() == null) {

			netSataus = false;
		}
		return netSataus;
	}

	@Override
	public void onArriveDestination() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onArrivedWayPoint(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onCalculateRouteFailure(int arg0) {
		showToast("路径规划出错" + arg0);
		pop_address_nav_tv.setText("算路");
		mIsCalculateRouteSuccess = false;

	}

	@Override
	public void onCalculateRouteSuccess() {
		showToast("算路成功");
		mAmapNavi = AMapNavi.getInstance(this);
		AMapNaviPath naviPath = mAMapNavi.getNaviPath();
		if (naviPath == null) {
			return;
		}
		int com_navPath = naviPath.getAllLength();
		System.out.println(com_navPath);// **************************************总导航距离

		double com_navPath_renum;
		// 判断距离是否大于1000 大于1000显示公里，小于1000显示米
		if (com_navPath > 1000 || com_navPath == 1000) {
			com_navPath_renum = com_navPath / 1000;
			navPath = String.valueOf(com_navPath_renum) + "公里";
		} else if (com_navPath < 1000) {
			com_navPath_renum = com_navPath;
			navPath = String.valueOf(com_navPath_renum) + "米";
		}
		pop_address_nav_tv.setText(navPath);

		// 获取路径规划线路，显示到地图上
		mRouteOverLay.setRouteInfo(naviPath);
		mRouteOverLay.addToMap();
		if (mIsMapLoaded) {
			mRouteOverLay.zoomToSpan();
		}

	}

	@Override
	public void onEndEmulatorNavi() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onGetNavigationText(int arg0, String arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onGpsOpenStatus(boolean arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onInitNaviFailure() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onInitNaviSuccess() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onLocationChange(AMapNaviLocation arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onNaviInfoUpdate(NaviInfo arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	@Deprecated
	public void onNaviInfoUpdated(AMapNaviInfo arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onReCalculateRouteForTrafficJam() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onReCalculateRouteForYaw() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onStartNavi(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTrafficStatusUpdate() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onMapLoaded() {
		mIsMapLoaded = true;
		if (mRouteOverLay != null) {
			mRouteOverLay.zoomToSpan();

		}
	}

	@Override
	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTextChanged(CharSequence s, int start, int before, int count) {
		String newText = s.toString();
		// 输入信息的回调方法
		Inputtips inputTips = new Inputtips(ComAddressListavt.this,
				new InputtipsListener() {
					@Override
					public void onGetInputtips(List<Tip> tipList, int rCode) {
						adaList.clear();
						if (tips == null) {
							tips = new ArrayList<Tip>();
						} else {
							tips.clear();
						}
						if (tipList != null) {
							tips.clear();
						}
						tips.addAll(tipList);
						for (Tip tip : tipList) {
							adaList.add(tip.getName());
							Log.i(TAG, "name :" + tip.getName());
						}
						serchAdapter = new ArrayAdapter(
								getApplicationContext(), R.layout.route_inputs,
								adaList);
						serchEditText.setAdapter(serchAdapter);
						serchAdapter.notifyDataSetChanged();
					}
				});

		// 发送输入提示请求
		// 第一个参数表示提示关键字，第二个参数默认代表全国，也可以为城市区号
		try {
			inputTips.requestInputtips(newText, "");
		} catch (com.amap.api.services.core.AMapException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@Override
	public void afterTextChanged(Editable s) {
		// TODO Auto-generated method stub

	}

	@Override
	public void OnUpdateTrafficFacility(TrafficFacilityInfo arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hideCross() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hideLaneInfo() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void showCross(AMapNaviCross arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void showLaneInfo(AMapLaneInfo[] arg0, byte[] arg1, byte[] arg2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	@Deprecated
	public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void notifyParallelRoad(int arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onArriveDestination(NaviStaticInfo arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onCalculateMultipleRoutesSuccess(int[] arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void updateAimlessModeStatistics(AimLessModeStat arg0) {
		// TODO Auto-generated method stub
		
	}

}
